package com.mall.alipay.controller;

import com.alipay.api.AlipayApiException;
import com.mall.alipay.feign.OrderFeign;
import com.mall.alipay.template.AlipayTemplate;
import com.mall.entity.bargain.BgOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author White
 * @version 1.0
 * @email 616769721@qq.com
 * @date 2021/7/22 17:02
 */
@RestController
@RequestMapping("/aliPay")
public class AlipayController {

    @Autowired
    private AlipayTemplate alipayTemplate;

    /**
     * 发起支付接口
     * @param id 订单id
     * @return 支付页面
     * @throws AlipayApiException 阿里支付接口异常
     */
    @RequestMapping( "/payOrder/{id}")
    public String doPay(@PathVariable Long id) throws AlipayApiException {
        return alipayTemplate.doPay(id);
    }

    /**
     * 支付信息回调接口
     */
    @RequestMapping("/paySuccess")
    public void paySuccess(HttpServletRequest request){
        String outTradeNo = request.getParameter("out_trade_no");
        System.out.println("outTradeNo->"+outTradeNo);
        alipayTemplate.paySuccess(outTradeNo);
    }
}
